<?php
/**
 * Created by PhpStorm.
 * User: 17628
 * Date: 2021-11-17
 * Time: 9:19
 */

namespace app\api\controller;


use app\admin\model\Banner;
use app\admin\model\GoodsCase;
use app\admin\model\Goods;
use app\common\controller\Api;
use think\Env;

class Classify extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    //分类页面
    //图片加标题
    public function banner()
    {
        $model = new Banner();
        $list = $model
            ->where('type', 2)
            ->field('id,name,image')
            ->select();
        foreach ($list as $v) {
            $v['image'] = Env::get('app.yuming') . $v['image'];
        }
        return sucessMsg('200', '获取成功', $list);
    }

    //商品分类
    public function classify()
    {
        $model = new GoodsCase();
        $list = $model
            ->field('id,name')
            ->select();
        return sucessMsg('200', '获取成功', $list);
    }

    //商品列表
    public function goods()
    {
        $cate_id = input('cate_id');
        $list = Goods::where('cate_id', $cate_id)
            ->field('id,title,desc,price,discounts_price,image,cate_id')
            ->select();
        foreach ($list as $v) {
            $v['image'] = Env::get('app.yuming') . $v['image'];
        }
        return sucessMsg('200','获取成功',$list);
    }

}